package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/2/27
 * @Description:
 */
@RestController
@RequestMapping("tags")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping
    public List<Tag> getList(){
        return tagService.list();
    }

    // TODO  为了业务的严谨性 需要考虑学生和标签的关系表中的数据
    @DeleteMapping("{id}")
    public boolean deleteById(@PathVariable Integer id){
       return  tagService.removeById(id);
    }


    @PostMapping
    public Tag  addTag(@RequestBody Tag tag){
        tag.setCreatedate(new Date());
        tagService.save(tag);
        return tag;
    }

    // 根据标签的id  查询标签
    @GetMapping("{id}")
    public Tag  getById(@PathVariable Integer id){
      return   tagService.getById(id);
    }

}
